
clear

tt_vec=[0.25 0.50 0.75]';

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        % FILES: QUANTILE UNDER EXOG
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        
path_results='./';

file_unc_vec=['output_qreg_unconstrained_tau25_config1'; ...
              'output_qreg_unconstrained_tau50_config1'; ...
              'output_qreg_unconstrained_tau75_config1'];
              
file_constr_vec=['output_qreg_constrained_tau25_config2'; ...
                 'output_qreg_constrained_tau50_config2'; ...
                 'output_qreg_constrained_tau75_config2'];

file_qlin_vec=['output_qreg_lin_tau25_config5'; ...
               'output_qreg_lin_tau50_config5'; ...
               'output_qreg_lin_tau75_config5'];

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        % FILES: MEAN CASE
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

path_results_mean=path_results;

file_mean_unc='output_mean_unconstrained_tau50_config3';
file_mean_constr='output_mean_constrained_tau50_config4';

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        % START LOOP
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for tt=1:size(tt_vec,1),

    tau=tt_vec(tt,1);
    varlist='tau tt_vec x2_text';
    
    x2_text=char('low income group','middle income group','high income group');
    vartext_unc='p_interest y_interest_univ y_interest qhat CI_logQ_low CI_logQ_high DWL DWL_pertax DWL_perinc';
    vartext_constr='p_interest y_interest_univ y_interest qhat DWL DWL_pertax DWL_perinc';
    vartext_qlin='p_interest y_interest_univ y_interest qhat DWL DWL_pertax DWL_perinc';

    eval(['load ' path_results file_unc_vec(tt,:) '.mat ' vartext_unc]);
          
    x1_interest_72500=p_interest(y_interest==log(72500));
    x1_interest_42500=p_interest(y_interest==log(42500));
    x1_interest_57500=p_interest(y_interest==log(57500));

    g_unconstr=qhat;
    g_unconstr_72500=qhat(y_interest==log(72500));
    g_unconstr_42500=qhat(y_interest==log(42500));
    g_unconstr_57500=qhat(y_interest==log(57500));

    DWL_unconstr=DWL;
    DWL_pertax_unconstr=DWL_pertax;
    DWL_perinc_unconstr=DWL_perinc;

    CI_logQ_low_symmetrical_joint=CI_logQ_low; % modified, omitting transpose [Monday, June 13, 2016  22:44]
    CI_logQ_high_symmetrical_joint=CI_logQ_high; % modified, omitting transpose [Monday, June 13, 2016  22:44]
    
    clear p_interest y_interest  y_interest_univ qhat CI_logQ_low CI_logQ_high
    
    eval(['load ' path_results file_constr_vec(tt,:) '.mat ' vartext_constr]);
          
    g_constr=qhat;
    g_constr_72500=qhat(y_interest==log(72500));
    g_constr_42500=qhat(y_interest==log(42500));
    g_constr_57500=qhat(y_interest==log(57500));

    x2_interest_univ=y_interest_univ;
    x2_interest=y_interest;
    x1_interest=p_interest;
   
    DWL_constr=DWL;
    DWL_pertax_constr=DWL_pertax;
    DWL_perinc_constr=DWL_perinc;
                        
    clear p_interest y_interest y_interest_univ qhat DWL DWL_pertax DWL_perinc

    varlist=[varlist ' x1_interest* x2_interest* g_unconstr* g_constr* CI* DWL*'];

    eval(['load ' path_results file_qlin_vec(tt,:) '.mat ' vartext_qlin]);
          
    g_qlin=qhat;
    g_qlin_72500=qhat(y_interest==log(72500));
    g_qlin_42500=qhat(y_interest==log(42500));
    g_qlin_57500=qhat(y_interest==log(57500));

    DWL_qlin=DWL;
    DWL_pertax_qlin=DWL_pertax;
    DWL_perinc_qlin=DWL_perinc;
                        
    clear p_interest y_interest y_interest_univ qhat DWL DWL_pertax DWL_perinc
   
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        % MEAN CASE
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    if tau==0.5,

        x2_text=char('low income group','middle income group','high income group');
        vartext_unc='p_interest y_interest_univ y_interest qhat CI_logQ_low CI_logQ_high';
        vartext_constr='p_interest y_interest_univ y_interest qhat';

        eval(['load ' path_results_mean file_mean_unc '.mat ' vartext_unc]);
              
        x1_interest_72500_mean=p_interest(y_interest==log(72500));
        x1_interest_42500_mean=p_interest(y_interest==log(42500));
        x1_interest_57500_mean=p_interest(y_interest==log(57500));
    
        g_mean_unconstr=qhat;
        g_mean_unconstr_72500=qhat(y_interest==log(72500));
        g_mean_unconstr_42500=qhat(y_interest==log(42500));
        g_mean_unconstr_57500=qhat(y_interest==log(57500));
    
        CI_logQ_mean_low_symmetrical_joint=CI_logQ_low;
        CI_logQ_mean_high_symmetrical_joint=CI_logQ_high;
    
        clear p_interest y_interest  y_interest_univ qhat CI_logQ_low CI_logQ_high
    
        eval(['load ' path_results_mean file_mean_constr '.mat ' vartext_constr]);
              
        g_mean_constr=qhat;
        g_mean_constr_72500=qhat(y_interest==log(72500));
        g_mean_constr_42500=qhat(y_interest==log(42500));
        g_mean_constr_57500=qhat(y_interest==log(57500));
    
        x2_interest_univ_mean=y_interest_univ;
        x2_interest_mean=y_interest;
        x1_interest_mean=p_interest;
           
        clear p_interest y_interest_univ y_interest qhat 

        varlist=[varlist ' g_mean_*'];
        
    end;
    
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        % SAVE RESULTS
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    eval(['save ./data_results_tau' num2str(100*tau) '.mat ' varlist]);
    
    clear g_unconstr* g_constr* *interest* varlist
    
end;

    %

